﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;

namespace chapter1._6Web.Handlers
{
    /// <summary>
    /// ProductHandler 的摘要说明
    /// </summary>
    public class ProductHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int typeId = int.Parse(context.Request["id"]);
            using (EFC6Entities db = new EFC6Entities())
            {
                var data = db.products.Where(p=>p.type==typeId).ToList();
                //返回一个json字符串
                //"{name:11,age:18}"
                JavaScriptSerializer js = new JavaScriptSerializer();
                context.Response.Write(js.Serialize(data));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}